import org.geotools.data.FileDataStore;
import org.geotools.data.FileDataStoreFinder;
import org.geotools.data.simple.SimpleFeatureSource;
import org.geotools.map.FeatureLayer;
import org.geotools.map.Layer;
import org.geotools.map.MapContent;
import org.geotools.styling.SLD;
import org.geotools.styling.Style;
import org.geotools.swing.JMapFrame;
import org.geotools.swing.data.JFileDataStoreChooser;

import java.io.File;

public class QuickStart {
    public static void main(String[] args) throws Exception{
        /**
         * get shp file
         */
        // get file by dialog
//         File file = JFileDataStoreChooser.showOpenFile("shp", null);
        // get file by url
        File file = new File("src/main/resources/china_boundary/china_boundary.shp");
        if(file == null) return;

        /**
         * get featureSource
         *
         * featureSource aim to manipulate feature
         */
        FileDataStore store = FileDataStoreFinder.getDataStore(file);
        SimpleFeatureSource featureSource = store.getFeatureSource();

        /**
         * render shp
         * a map -> many layers
         */
        MapContent map = new MapContent();
        map.setTitle("show map");

        Style style = SLD.createSimpleStyle(featureSource.getSchema());
        Layer layer = new FeatureLayer(featureSource, style);
        map.addLayer(layer);

        JMapFrame.showMap(map);
    }
}
